<template>
	<view class="pageBox" :style="{paddingTop: statusBarHeight + 44 + 'px',}">
		<view class="topHead flex-between" :style="{top: statusBarHeight + 'px',}">
			<uni-icons type="back" size="24" @click="goBack"></uni-icons>
			<view class="title">
				申请服务中心
			</view>
			<view class="right" @click="onRight">
				申请服务说明
			</view>
		</view>
		<view class="iptBox flex-between">
			<input type="text" class="input" placeholder="申请人姓名" v-model="form.username">
			<button class="recordBtn" :plain="true" @click="onRecordBtn">申请记录</button>
		</view>
		<input type="text" class="ipt" placeholder="申请人电话" v-model="form.mobile">

		<button :plain="true" :class="[disabled ? 'btn btn2' : 'btn']" @click="onBtn" :disabled="disabled">确认申请</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: "",
				form: {
					username: "",
					mobile: "",
				},
				disabled: false,
			}
		},
		onLoad() {
			this.statusBarHeight = this.$mySysInfo().top;
		},
		onShow() {
			this.getStatus();
		},
		methods: {
			onRight() {
				uni.navigateTo({
					url: '/serviceCenter/serviceNote?from=申请服务中心&type=1'
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			onRecordBtn() {
				uni.navigateTo({
					url: '/serviceCenter/serviveRecord?from=申请服务中心&type=1'
				})
			},
			onBtn() {
				if (!this.form.username) {
					uni.showToast({
						icon: "none",
						title: "请输入申请人姓名",
						duration: 1500
					})
					return;
				}
				
				if (!this.form.mobile) {
					uni.showToast({
						icon: "none",
						title: "请输入申请人电话",
						duration: 1500
					})
					return;
				}
				this.$post({
					module: "User",
					interface: "3002",
					data: {
						realName: this.form.username,
						mobile: this.form.mobile,
						province_id: "0",
						city_id: "0",
						type: "1",
					},
				}).then(res => {
					uni.showToast({
						icon: "none",
						title: "操作成功",
						duration: 1500
					})
					setTimeout(() => {
						this.goBack();
					}, 1000)
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			// 获取服务中心申请信息
			getStatus() {
				this.$post({
					module: "User",
					interface: "3003",
					data: {
						type: "1",
					},
				}).then(res => {
					// console.log(res)
					if(res.status === '') {
						this.disabled = false;
					} else if(res.status == 0 || res.status == 1) {
						this.disabled = true;
					} else {
						this.disabled = false;
					}
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.pageBox {
		padding: 0 32rpx;
		.topHead {
			background-color: #ffffff;
			height: 88rpx;
			width: 100%;
			padding: 0 32rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 3;
		
			.title {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				position: absolute;
				top: 22rpx;
				left: 50%;
				transform: translate(-50%, 0);
			}
		
			.right {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #F2615F;
			}
		}

		.iptBox {
			.input {
				width: 256rpx;
				height: 80rpx;
				background: #f9f9f9;
				border-radius: 16rpx;
				margin-top: 28rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				line-height: 44rpx;
				padding-left: 16rpx;
			}

			.recordBtn {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				line-height: 44rpx;
				padding: 0;
				margin: 0;
				border: none;
			}
		}

		.ipt {
			width: 100%;
			height: 80rpx;
			background: #f9f9f9;
			border-radius: 16rpx;
			margin-top: 28rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #000000;
			line-height: 44rpx;
			padding-left: 16rpx;
		}

		.btn {
			font-size: 36rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #ffffff;
			width: 606rpx;
			height: 104rpx;
			background: #F2615F;
			border-radius: 52rpx;
			border: none;
			padding: 0;
			margin: 236rpx auto 0;
		}
		.btn2 {
			background: #bebebe;
		}
	}
</style>
